package com.gin.supermarket_inventory_system.commodity.dto.form;

import com.gin.database.validation.EntityId;
import com.gin.supermarket_inventory_system.commodity.entity.CommodityPo;
import com.gin.supermarket_inventory_system.commodity.service.CommodityProducerService;
import com.gin.supermarket_inventory_system.commodity.service.CommodityTypeService;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Pattern;
import lombok.Getter;
import lombok.Setter;
import org.springframework.beans.BeanUtils;

/**
 * 添加商品信息
 * @since : 2023/10/9 16:31
 * @author : ginstone
 * @version : v1.0.0
 **/
@Getter
@Setter
@Schema(description = "表单对象:添加商品信息")
public class CommodityAddForm {
    @Schema(description = "名称")
    @Pattern(regexp = "[^/]+")
    @NotEmpty
    String name;

    @Schema(description = "商品类型ID")
    @EntityId(service = CommodityTypeService.class)
    @NotNull
    Long typeId;

    @Schema(description = "商品生产商ID")
    @EntityId(service = CommodityProducerService.class)
    @NotNull
    Long producerId;

    public CommodityPo toPo() {
        final CommodityPo po = new CommodityPo();
        BeanUtils.copyProperties(this, po);
        return po;
    }
}